import { safeGetLocalStorage } from 'src/utils/index';

export default {
  namespaced: true,
  state: {
    loading: false,
    loginTimeOutVisible: false,
    baseAppId: '',
    token: '',
    scfpCstId: '',
    scfpUsrId: '',
    userInfo: safeGetLocalStorage('userInfo', {}),
    styleObject: {},
    isAdmin: '',
    loginType: 0,
    adToken: ''
  },
  mutations: {
    setAdToken(state, adToken) {
      state.adToken = adToken;
    },
    setScfpCstId(state, scfpCstId) {
      state.scfpCstId = scfpCstId;
    },
    setScfpUsrId(state, scfpUsrId) {
      state.scfpUsrId = scfpUsrId;
    },
    setToken(state, token) {
      state.token = token;
    },
    setBaseAppId(state, baseAppId) {
      state.baseAppId = baseAppId;
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo;
    },
    setLoginTimeOutVisible(state, loginTimeOutVisible) {
      state.loginTimeOutVisible = loginTimeOutVisible;
    },
    setLoading(state, loading) {
      state.loading = loading;
    },
    setIsAdmin(state, isAdmin) {
      state.isAdmin = isAdmin;
    },
    setLoginType(state, loginType) {
      state.loginType = loginType;
    },
    setStyleObject(state, styleObject) {
      if (Object.prototype.toString(styleObject) === '[object Object]') {
        state.styleObject = Object.assign(state.styleObject, styleObject);
      }
    }
  },
  getters: {
    getAdToken(state) {
      return state.adToken;
    },
    getScfpCstId(state) {
      return state.scfpCstId;
    },
    getScfpUsrId(state) {
      return state.scfpUsrId;
    },
    getBaseAppId(state) {
      return state.baseAppId;
    },
    getToken(state) {
      return state.token;
    },
    getLoginTimeOutVisible(state) {
      return state.loginTimeOutVisible;
    },
    getLoading(state) {
      return state.loading;
    },
    getUserInfo(state) {
      return state.userInfo;
    },
    getIsAdmin(state) {
      return state.isAdmin;
    },
    getStyleObject(state) {
      return state.styleObject;
    },
    getLoginType(state) {
      return state.loginType;
    }
  }
};
